﻿function ajaxLoginbar(w)
{
	//参数说明:w=-1,0,1分别指"退出","初始化"和"登陆"
	var uName="";
	var uPass="";
	if(w==null) w=0;
	if(w==-1)
	{
		$.ajax({
			type:		"get",
			dataType:	"json",
			data:		"time="+(new Date().getTime()),
			url:		site.Dir + "ajax/user.aspx?oper=ajaxUserInfo",
			success:	function(data){
				window.location.href=site.LogoutUrl+"?userkey="+data.userkey;
			}
		});
		return;
	}
	if(w==1)
	{
		uName=$("#loginBarName").val();
		uPass=$("#loginBarPass").val();
		if(!uName || !uPass)
		{
			window.location.href = site.LoginUrl;
			return;
		}
		$("btnLoginbar").attr("disabled","disabled");
	}
	$.ajax({
		type:		"post",
		dataType:	"json",
		data:		"name="+escape(uName)+"&pass="+escape(uPass)+"&state="+w,
		url:		site.Dir + "ajax/user.aspx?oper=ajaxLoginbar&time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			if(d.result!="1" && w==1)
				alert(d.returnval);
			else
			{
var _ajaxLoginbar = "<div class=\"loginbar\">"
_ajaxLoginbar += "<ul class=\"navigation\">"
_ajaxLoginbar += "<li class=\"icon\"></li>"
if(d.result == "0")
{
	_ajaxLoginbar += "<li><a href=\"" + site.LoginUrl + "\">登录</a></li>"
	_ajaxLoginbar += "<li class=\"hr\">|</li>"
	_ajaxLoginbar += "<li><a href=\"" + site.RegisterUrl + "\">注册</a></li>"
	_ajaxLoginbar += "<li><a href=\"" + site.GetPasswordUrl + "\">忘记密码</a></li>"
}
else
{
	_ajaxLoginbar += "<li>欢迎:<font title=\"分组:" + d.groupname + "&#10;当前点数:" + d.points + "\"><b>" + d.username + "</b></font></li>"
	_ajaxLoginbar += "<li><a href=\"" + site.Dir + "user/index/index.aspx\">个人中心</a></li>"
	if(d.adminid != "0")
	{
		_ajaxLoginbar += "<li class=\"hr\">|</li>"
		_ajaxLoginbar += "<li><a href=\"" + site.Dir + "admin/login.htm?adminid=" + d.adminid + "\" target=\"_blank\">管理中心</a></li>"
	}
	_ajaxLoginbar += "<li class=\"hr\">|</li>"
	_ajaxLoginbar += "<li><a href=\"" + site.LogoutUrl + "?userkey=" + d.userkey + "\">退出</a></li>"
}
_ajaxLoginbar += "</ul>"
_ajaxLoginbar += "</div>"
				$("#ajaxLoginbar").html(_ajaxLoginbar);
			}
		}
	});
}
///////////////////////////////////////////////////////////////////////////
//特约专题
///////////////////////////////////////////////////////////////////////////
function ajaxPluginSpecialList(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxPluginSpecialList";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_SpecialList, site.Dir + "templates/_speciallist.htm", oDiv, site.Dir + "_data/style/p_speciallist.js", "", "js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_SpecialList, site.Dir + "templates/_speciallist.htm", oDiv, site.Dir + "_data/html/p_speciallist.htm", "", "html");
	else
		ExecuteTemplate($$_JSON_SpecialList, site.Dir + "templates/_speciallist.htm", oDiv);
}
function ajaxGo2View(ccId,id)
{
	$.ajax({
		type:		"post",
		dataType:	"json",
		data:		"contentid="+id+"&channelid="+ccId+"&time="+(new Date().getTime()),
		url:		site.Dir + "ajax/content.aspx?oper=ajaxGo2View",
        	error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			window.open(d.returnval);
		}
	});
}
function ajaxViewCount(cType,id,randomid,needadd)
{
	var addit = needadd == false ? 0 : 1;
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxViewCount&id="+id+"&addit="+addit+"&cType="+cType+"&time="+(new Date().getTime()),
		url:		site.Dir + "ajax/content.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			$("#ajaxViewCount_"+id+"_"+randomid).text(d.count);
		}
	});
}
function replaceContentTags(ccid,cType,taglist,bodyid)
{
	try{
		var elms1 = $("#"+bodyid+" a");
		for (i = 0; i < elms1.length; i++){elms1[i].title="";}
		var elms2 = $("#"+bodyid+" img");
		for (i = 0; i < elms2.length; i++){elms2[i].alt="";}
		var returnhtml=$("#"+bodyid).html();
		var tags=taglist.split(',');
		for (i = 0; i < tags.length; i++) {
			if(tags[i].length>1)//只取2个字符以上的
			{
				returnhtml=returnhtml.replace(tags[i],"<a href='"+site.Dir + "extends/search/index.aspx?type="+cType+"&k="+escape(tags[i])+"&t=tag' target='_blank'><span class='tag'>"+tags[i]+"</span></a>");
			}
		}
		$("#"+bodyid).html(returnhtml);
	}
	catch(e){}
}
function addFavorite(ccid,cType,id)
{
	$.ajax({
		type:		"get",
		dataType:	"html",
		data:		"oper=addFavorite&id="+id+"&ccid="+ccid+"&cType="+cType+"&time="+(new Date().getTime()),
		url:		site.Dir + "ajax/content.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			alert(d);
		}
	});
}
var _closeTimer = -1;
function Go2PageForm(url)
{
	var oDialog = new jcms$$Dialog('1', '确认框', 290, 130, 'success', false);
	oDialog.init();
	var sHtml = '<form id="Go2PageForm"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">\
			<tr><td height="30" align="left"><span id="closetimer"></span></td></tr>\
			<tr><td height="30" align="left">验证：<input name="txtGo2Code" type="text" maxlength="6" id="txtGo2Code" class="ipt" style="width:50px;ime-mode:disabled;" onpaste="return false"  /> <img onclick="this.src=jcms$$SetUrlRefresh(\''+site.Dir+'plus/getcode3.aspx'+'\');" src="'+site.Dir+'plus/getcode3.aspx?t='+(new Date().getTime())+'" align="absmiddle" style="cursor: pointer" alt="不区分大小写,点击换一张" title="不区分大小写,点击换一张" /><img id="imgRead" src="'+site.Dir+'publicstyle/maintb.gif" align="absmiddle" style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="PlayCodeVoice();" />\
			<span id="player"></span></td></tr>\
			<tr><td height="40" align="left"><input type="button" value="确认" onclick="Go2PageCheck(\''+url+'\');" />&nbsp;&nbsp;<input type="button" value="取消" onclick="Go2PageStop();" /></td></tr>\
		</table></form>\
	';
	oDialog.event(sHtml,'');
	Go2PageStart();
}
function Go2PageCheck(url){
	var uCode=$("#txtGo2Code").val();
	if(uCode != ReadCookie("ValidateCode")){
		alert('验证码错误');
		$("#txtGo2Code").focus();
		return;
	}
	window.open(site.Dir + "plus/"+url+"&code="+uCode);
	Go2PageStop();
}
function Go2PageStart(){
	_closeTimer = 30;
	Go2PageAutoClose(_closeTimer, "closetimer");
}
function Go2PageStop(){
	_closeTimer = - 1;
	Go2PageAutoClose(_closeTimer, "closetimer");
}
function Go2PageAutoClose(secs, spanid){
	if($$(spanid) == null)
		return;
	if(secs > 0) 
	{
		_closeTimer = secs - 1;
		$('#'+spanid).html('还有' + _closeTimer + '秒自动关闭');
		window.setTimeout("Go2PageAutoClose(" + _closeTimer + ",'" + spanid + "')", 1000);
	} 
	else if(secs == 0) 
	{
		_closeTimer = -1;
		Go2PageAutoClose(_closeTimer,spanid);
	} 
	else
	{
		new jcms$$Dialog().reset();
	}
}
/*选项卡*/
function jTab(Id, tId, EclassName, iBeHavior){
	if(!document.getElementById(Id))return;
	if(iBeHavior==null)iBeHavior='mouseover';
	if(EclassName==null)EclassName='more';
	var self=this;
	var links=document.getElementById(Id).getElementsByTagName('a');
	if(links.length==0)return;

	this.init=function(){
		for(var i=0;i<links.length;i++){
			eval("links[i].on"+iBeHavior+"=function(e){return self.itab(this);};");
			links[i].onclick=function(){
				return (this.href.indexOf('javascript:')>-1 || this.href.indexOf('#')<0 || this.className==EclassName);
			};
			links[i].onfocus=function(e){
				this.blur();
			};
		}
		self.itab(links[0]);
	};
	this.itab=function(o){
		if(o.href.indexOf('javascript:')>-1 || o.href.indexOf('#')<0 || o.className==EclassName){return true;}
		for(var i=0;i<links.length;i++){
			if(links[i].className!=EclassName)links[i].className='';
		}
		o.className='s';
		var url=o.href.substring(o.href.indexOf('#')+1);
		this.showDiv(url);
		return false;
	};
	this.showDiv=function(tDiv){
		if(document.getElementById(tId) && document.getElementById(tDiv)){
			document.getElementById(tId).innerHTML=document.getElementById(tDiv).innerHTML;
			jTab_img_border(document.getElementById(tId));
			//jTab_blank_link(document.getElementById(tId));
			jTab_set_className(document.getElementById(tId));
		}
	};
	this.createDiv=function(id){
		var div=document.createElement('div');
		div.style.display='none';
		div.id=id;
		document.body.appendChild(div);
		return div;
	};
	this.init();
}

function jTab_img_border(obj){
	var li = obj.getElementsByTagName('li');
	var img = null;
	var bc = '#333';
	for(var i=0;i<li.length;i++){
		img = li[i].getElementsByTagName('img');
		for(var j=0;j<img.length;j++){
			bc = img[j].style.borderColor;
			img[j].onmouseover=function(){this.style.borderColor='#f60';};
			img[j].onmouseout=function(){this.style.borderColor=bc;};
		}
	}
}

function jTab_blank_link(obj){
	obj=obj==null?document:obj;
	var links = obj.getElementsByTagName('a');
	for(var j=0;j<links.length;j++){
		links[j].setAttribute('target','_blank');
	}
}

function jTab_set_className(obj){
	obj=obj==null?document:obj;
	this.initialize=function(){
		var ename='';
		var links=obj.getElementsByTagName('a');
		for(var i=0;i<links.length;i++){
			ename=links[i].className;
			if(ename=='new' || ename=='hot'){
				links[i].style.position='relative';
				this.createDiv(links[i],ename);
			}
		}
	};
	this.createDiv=function(ilink, en){
		var a=document.createElement('div');
		a.className='icon_'+en;
		a.style.left=parseInt(ilink.offsetLeft-15)+'px';
		a.style.top=parseInt(ilink.offsetTop-15)+'px';
		ilink.parentNode.appendChild(a);
		return a;
	};
	this.initialize();
}
/*内容滚动*/
function jScrollText(content,btnPrevious,btnNext,autoStart,timeout,isSmoothScroll)
{
	this.Speed = 10;
	this.Timeout = timeout;
	this.stopscroll =false;//是否停止滚动的标志位
	this.isSmoothScroll= isSmoothScroll;//是否平滑连续滚动
	this.LineHeight = 20;//默认高度。可以在外部根据需要设置
	this.NextButton = this.$(btnNext);
	this.PreviousButton = this.$(btnPrevious);
	this.ScrollContent = this.$(content);
	if(!this.ScrollContent) return;
	this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;//为了平滑滚动再加一遍

	if(this.PreviousButton)

	{
		this.PreviousButton.onclick = this.GetFunction(this,"Previous"); 
		this.PreviousButton.onmouseover = this.GetFunction(this,"MouseOver");
		this.PreviousButton.onmouseout = this.GetFunction(this,"MouseOut");
	}
	if(this.NextButton){
		this.NextButton.onclick = this.GetFunction(this,"Next");
		this.NextButton.onmouseover = this.GetFunction(this,"MouseOver");
		this.NextButton.onmouseout = this.GetFunction(this,"MouseOut");
	}
	this.ScrollContent.onmouseover = this.GetFunction(this,"MouseOver");
	this.ScrollContent.onmouseout = this.GetFunction(this,"MouseOut");

	if(autoStart)
	{
		this.Start();
	}
}

jScrollText.prototype = {

	$:function(element)
	{
		return document.getElementById(element);
	},
	Previous:function()
	{
		this.stopscroll = true;
		this.Scroll("up");
	},
	Next:function()
	{
		this.stopscroll = true;
		this.Scroll("down");
	},
	Start:function()
	{
		if(this.isSmoothScroll)
		{
			this.AutoScrollTimer = setInterval(this.GetFunction(this,"SmoothScroll"), this.Timeout);
		}
		else
		{		
			this.AutoScrollTimer = setInterval(this.GetFunction(this,"AutoScroll"), this.Timeout);
		}
	},
	Stop:function()
	{
		clearTimeout(this.AutoScrollTimer);
		this.DelayTimerStop = 0;
	},
	MouseOver:function()
	{	
		this.stopscroll = true;
	},
	MouseOut:function()
	{
		this.stopscroll = false;
	},
	AutoScroll:function()
	{
		if(this.stopscroll) 
		{
			return;
		}
		this.ScrollContent.scrollTop++;
		if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
		{
			this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Speed);
		}
		else
		{
			if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
			{
				this.ScrollContent.scrollTop = 0;
			}
			clearTimeout(this.ScrollTimer);
			//this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
		}
	},
	SmoothScroll:function()
	{
		if(this.stopscroll) 
		{
			return;
		}
		this.ScrollContent.scrollTop++;
		if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
		{
			this.ScrollContent.scrollTop = 0;
		}
	},
	Scroll:function(direction)
	{

		if(direction=="up")
		{
			this.ScrollContent.scrollTop--;
		}
		else
		{
			this.ScrollContent.scrollTop++;
		}
		if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
		{
			this.ScrollContent.scrollTop = 0;
		}
		else if(parseInt(this.ScrollContent.scrollTop)<=0)
		{
			this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
		}
		
		if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
		{
			this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Speed);
		}
	},
	GetFunction:function(variable,method,param)
	{
		return function()
		{
			variable[method](param);
		}
	}
}